package com.smzd.ccms.business;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.smzd.ccms.dao.TemplateDao;
import com.smzd.ccms.domain.Site;
import com.smzd.ccms.domain.Template;
import com.smzd.core.dao.IDao;
import com.smzd.framework.core.business.AbstractFGService;
import com.smzd.framework.utils.db.FGRowConverter;
import com.smzd.utils.SessionHolder;

@Service
public class TemplateService extends AbstractFGService<Template> {
    @Autowired
    private TemplateDao dao;
    
    @Override
    protected IDao<Template> getDao() {
        return dao;
    }
    
    @Override
    public FGRowConverter<Template> getConverter() {
        return converter;
    }

    private static FGRowConverter<Template> converter = new FGRowConverter<Template>() {
        @Override
        public Object[] convert(Template elem) {
			Site site = SessionHolder.getObject(Site.SESSION_KEY_CURRENT_SITE);
			boolean ismyown = site != null && site.getOwner().getId() - elem.getOwner().getId() == 0;
            Object[] fs = new Object[]{
                    elem.getId(),
                    elem.getName(),
                    elem.getDescription(),
                    elem.getPath(),
                    elem.getCapacity(),
                    elem.getType(),
                    ismyown
                };
                return fs;
        }
    };
    
}